<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <title>可视化帮助文档</title>
  <script type="text/javascript" src="linkMap.js?t=1709540437172"></script>
  <script>
    // 获取url传参
    function getQueryValue(name){
      var reg = new RegExp(`${name}=([^&]*)(&|$)`, 'i')
      var r = window.location.href.match(reg)
      if (r != null) return unescape(r[1])
      return null
    }

    // 获取当前系统语言
    function getLang() {
      var lang = getQueryValue('lang')
      if (!lang) {
        lang = (window._adoPremise && window._adoPremise.language) || 'zh-CN'
      }
      lang = lang.replace(/_/g, '-')
      return lang
    }

    function getTreeObj(){
      var docWin = window.frames[0]
      return docWin.myTree
    }

    function iframeOnLoad(){
      try{
        var treeObj = getTreeObj()
        showTopicByLink()
        if(location.href.indexOf('showAll') === -1){
          removeSnippetNode()
        }
      }catch(err){
        setTimeout(iframeOnLoad, 50)
      }
    }

    function showTopicByLink(){
      var key = getQueryValue('link')
      var title = getLinkTitle(key)
      var htmlLink = getHtmlLink(key)

      if(htmlLink){
        var treeNode = findTreeNode(htmlLink)
        initDocTitle(treeNode.name)
        showTopic(treeNode)
      }
    }

    function getLinkMapItem(key){
      for(var i in window.linkMap){
        var n = window.linkMap[i]
        if(n.vsKey === key){
          return n
        }
      }
      return null
    }

    function getHtmlLink(key){
      var link = ''
      var item = getLinkMapItem(key)
      if(item){
        var lang = getLang()
        var langKey = lang === 'zh-CN'? 'cnLink': 'enLink'
        link = item[langKey]
      }
      return link
    }

    function getLinkTitle(key){
      var title = ''
      var item = getLinkMapItem(key)
      if(item){
        var lang = getLang()
        var langKey = lang === 'zh-CN'? 'cnTitle': 'enTitle'
        title = item[langKey]
      }
      return title
    }

    function showTopic(treeNode){
      var docWin = window.frames[0]
      var treeObj = getTreeObj()
      var node = treeObj.getNodeByParam('name', treeNode.name)
      docWin.showTopic(treeNode)
    }

    function findTreeNode(link, treeNodes){
      var treeNode
      if(!treeNodes){
        var docWin = window.frames[0]
        treeNodes = docWin.mainNavi
      }
      for(var i=0; i<treeNodes.length; i++){
        var n = treeNodes[i]
        if(n.local === link){
           treeNode = n
           break
        } else if(n.children){
          treeNode = findTreeNode(link, n.children)
          if(treeNode) break
        }
      }
      return treeNode
    }

    function initDocTitle(subTitle){
      var lang = getLang()
      var title = '可视化帮助文档' 
      if(lang !== 'zh-CN'){
        title = 'Visual Help Manual'
      }
      if(subTitle){
        title = `${title} - ${subTitle}`
      }
      document.title = title
    }

    function initIframeUrl(){
      var lang = getLang()
      var url = 'en-US/index.html'
      if(!lang || lang === 'zh-CN'){
        url = 'zh-CN/index.html'
      }
      document.getElementById('topFrame').src = url
    }

    // 删除术语说明节点
    function removeSnippetNode(){
      var docWin = window.frames[0]
      var lis = docWin.document.querySelectorAll('#tree li.level_0')
      lis[lis.length-1].style.display = 'none'
    }
  </script>
</head>
<body>

<iframe id="topFrame" class="topFrame" src="" frameborder="0" scrolling="no" onload="iframeOnLoad()"></iframe>

<script>
  initDocTitle()
  initIframeUrl()
</script>

<style>
  html,body{
    height: 100%;
    overflow: hidden;
  }
  .topFrame{
    width:  100%;
    height: 100%;
  }
  .query_test{
    position: fixed;
    right: 20px;
    top: 20px;
  }
</style>
</body>
</html>